from BuildTree import *


class Solution:
    def trimBST(self, root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]:
        if not root: return None
        if root.val < low:
            # 删除其左子树
            return root.right
        if root.val > high:
            return root.left
        root.left = self.trimBST(root.left, low, high)
        root.right = self.trimBST(root.right, low, high)
        return root


if __name__ == '__main__':
    null = None
    root = build_tree_from_level_order([3, 0, 4, null, 2, null, null, 1])
    s = Solution()
    r = s.trimBST(root, 1, 3)
    print()
